#!/usr/bin/env python3

from datetime import datetime
from typing import Any, Dict, List, Optional

from pydantic import BaseModel, Field


class TextInput(BaseModel):
    """文本输入请求模型"""
    text: str = Field(..., description="需要处理的文本内容", min_length=1)
    user_id: Optional[str] = Field(None, description="用户ID，用于日志追踪")
    session_id: Optional[str] = Field(None, description="会话ID，用于关联处理")
    enable_classification: bool = Field(True, description="是否启用StructBERT文本分类")
    enable_summary: bool = Field(True, description="是否启用PALM2.0摘要生成")

class ActionClassification(BaseModel):
    """行动分类结果"""
    label: str = Field(..., description="分类标签（如：决策、任务、讨论等）")
    confidence: float = Field(..., description="置信度分数", ge=0.0, le=1.0)
    text_segment: str = Field(..., description="对应的文本片段")

class SummaryResult(BaseModel):
    """摘要生成结果"""
    summary: str = Field(..., description="生成的摘要文本")
    key_points: List[str] = Field(default_factory=list, description="关键要点列表")
    word_count: int = Field(..., description="摘要字数")

class ProcessingResult(BaseModel):
    """文本处理完整结果"""
    original_text: str = Field(..., description="原始输入文本")
    classifications: List[ActionClassification] = Field(default_factory=list, description="文本分类结果")
    summary: Optional[SummaryResult] = Field(None, description="摘要生成结果")
    processing_time: float = Field(..., description="处理耗时（秒）")
    model_versions: Dict[str, str] = Field(default_factory=dict, description="使用的模型版本信息")

class ProcessingResponse(BaseModel):
    """API响应模型"""
    success: bool = Field(..., description="处理是否成功")
    message: str = Field(..., description="响应消息")
    data: Optional[ProcessingResult] = Field(None, description="处理结果数据")
    request_id: str = Field(..., description="请求唯一标识")
    timestamp: datetime = Field(default_factory=datetime.now, description="响应时间戳")

class ErrorResponse(BaseModel):
    """错误响应模型"""
    success: bool = Field(False, description="处理失败")
    message: str = Field(..., description="错误消息")
    error_code: str = Field(..., description="错误代码")
    request_id: str = Field(..., description="请求唯一标识")
    timestamp: datetime = Field(default_factory=datetime.now, description="响应时间戳")

class HealthResponse(BaseModel):
    """健康检查响应模型"""
    status: str = Field(..., description="服务状态")
    models_loaded: Dict[str, bool] = Field(..., description="模型加载状态")
    memory_usage: Dict[str, Any] = Field(..., description="内存使用情况")
    uptime: float = Field(..., description="服务运行时间（秒）")
